﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityLayer0;
using DataAccess;

namespace Bu_layer
{
    public class DownloadDataManager
    {
        public void AddRecorder(RecorderInfo recorderInfo)
        {
            LoginDAL loginDAl = new LoginDAL();
            loginDAl.AddRecorder(recorderInfo);
        }

        public void GetFileInfoBase()
        {
            AccountManagerClient accountManagerClient = new AccountManagerClient();
            FileDataInfoBase[] filedata = accountManagerClient.FileDataInfoBase();
            long fileID = filedata[0].FileId;
            string fileName = filedata[0].FileName;
            FileFormat fileFormat = filedata[0].FileFormat;
            RecorderInfo[] recorderInfo = accountManagerClient.RecorderInfo();           
            AddFileInfo(fileID, recorderInfo[0], fileName, fileFormat);
        }

        public FileDataInfo[] CreateFileInfo(long fileID, string fileName, FileFormat fileFormat)
        { 
            List<FileDataInfo> fileDataInfoList = new List<FileDataInfo>();
            DateTime timeDownloaded = DateTime.Now;
            DateTime beginDownloaded = DateTime.Now;
            DateTime endDownloaded = DateTime.Now;
            string firstHash = "HJJUTKIJRGVRTHTRH";
            

            FileDataInfo fileDataInfo = new FileDataInfo(timeDownloaded, beginDownloaded, endDownloaded, firstHash);
            fileDataInfo.FileId = fileID;
            fileDataInfo.FileName = fileName;
            fileDataInfo.FileFormat = fileFormat;
            fileDataInfoList.Add(fileDataInfo);
            return fileDataInfoList.ToArray();
        }

        public void AddFileInfo(long fileID, RecorderInfo recorderInfo, string fileName, FileFormat fileFormat)
        {
            recorderInfo.FileDataInfo = CreateFileInfo(fileID, fileName, fileFormat);

            LoginDAL loginDAL = new LoginDAL();
            foreach (FileDataInfo files in recorderInfo.FileDataInfo)
            {
                loginDAL.AddFileInfo(files, recorderInfo.DeviceId);
            }
            
        }
    }
}
